'use strict';

/* Controllers */

angular.module('app')
.controller('AppCtrl', ['$scope', '$translate', '$localStorage', '$window','$rootScope', 
  function(              $scope,   $translate,   $localStorage,   $window,$rootScope ) {
      // add 'ie' classes to html
      var isIE = !!navigator.userAgent.match(/MSIE/i);
      isIE && angular.element($window.document.body).addClass('ie');
      isSmartDevice( $window ) && angular.element($window.document.body).addClass('smart');

      // config
      $scope.app = {
        name: 'IHAIBI',
        version: '1.3.3',
        // for chart colors
        color: {
          primary: '#7266ba',
          info:    '#23b7e5',
          success: '#27c24c',
          warning: '#fad733',
          danger:  '#f05050',
          light:   '#e8eff0',
          dark:    '#3a3f51',
          black:   '#1c2b36'
        },
        settings: {
          themeID: 9,
          navbarHeaderColor: 'bg-info dker',
          navbarCollapseColor: 'bg-info dk',
          asideColor: 'bg-black',
          headerFixed: true,
          asideFixed: false,
          asideFolded: false,
          asideDock: false,
          container: false
        }
      }

      // save settings to local storage
      if ( angular.isDefined($localStorage.settings) ) {
        $scope.app.settings = $localStorage.settings;
      } else {
        $localStorage.settings = $scope.app.settings;
      }
      $scope.$watch('app.settings', function(){
        if( $scope.app.settings.asideDock  &&  $scope.app.settings.asideFixed ){
          // aside dock and fixed must set the header fixed.
          $scope.app.settings.headerFixed = true;
        }
        // save to local storage
        $localStorage.settings = $scope.app.settings;
      }, true);


      function isSmartDevice( $window )
      {
          // Adapted from http://www.detectmobilebrowsers.com
          var ua = $window['navigator']['userAgent'] || $window['navigator']['vendor'] || $window['opera'];
          // Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
          return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/).test(ua);
        }

           //平台选择
  /*         $scope.platform = { isopen: false };
          $scope.platforms = {en:'媒资平台', de_DE:'影视平台', it_IT:'用户管理'};
          $scope.selectPlatform =  "媒资平台";
          $scope.setPlatform = function(platformKey, $event) {
          $scope.selectPlatform = $scope.platforms[platformKey];
          $scope.platform.isopen = !$scope.platform.isopen;
        }*/
        

        $scope.choosePlatformMedia = function(){
         $scope.$broadcast('platform', 1);
       }
       $scope.choosePlatformMovies = function(){
         $scope.$broadcast('platform', 2);
       }
       $scope.choosePlatformNetwork = function(){
        $scope.$broadcast('platform', 3);
      }
      $scope.choosePlatformCourse = function(){
       $scope.$broadcast('platform',4);
     }
     $scope.choosePlatformUser = function(){
      $scope.$broadcast('platform',5);
     }



//退出销毁登录状态。并且跳转到登录页面
$scope.logout = function () {
  console.log('router.js-loginflag:'+$rootScope.$state.isLogin);

  $rootScope.$state.isLogin = false;
  $rootScope.$state.go('login.signin');
  
};






}]);